package com.android.lovely.ui.widget

import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import androidx.core.view.isVisible
import com.android.lovely.databinding.LayoutSplashLoginBinding
import com.android.lovely.databinding.WidgetCreateRoleBottomBinding
import com.android.lovely.databinding.WidgetRoleTipBinding
import com.android.lovely.ui.viewmodel.CreateRoleViewModel
import com.kotlin.extensions.inflater.LayoutInflaterExt.layoutInflater

/**
 *
 * @author why
 * @date 2025/4/7 20:31
 */
class CreateRoleBottomWidget  @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

    private val mBinding by lazy {
        WidgetCreateRoleBottomBinding.inflate(layoutInflater, this, false)
    }
    private var listener:OnBottomClickListener ?= null

    private var isEdit = false

    init {
        addView(mBinding.root)
        mBinding.apply {
            preview.setOnClickListener {
                listener?.onPreview()
            }
            next.setOnClickListener {
                listener?.onNext()
            }
            back.setOnClickListener {
                listener?.onBack()
            }
        }
    }

    fun update(isEdit: Boolean, listener: OnBottomClickListener) {
        this.listener = listener
        this.isEdit = isEdit
        if(isEdit) {
            mBinding.preview.isVisible = true
            mBinding.llNext.isVisible = false
        } else {
            mBinding.preview.isVisible = false
            mBinding.llNext.isVisible = true
        }
    }

    fun update(isEdit: Boolean) {
        this.isEdit = isEdit
        if(isEdit) {
            mBinding.preview.isVisible = true
            mBinding.llNext.isVisible = false
        } else {
            mBinding.preview.isVisible = false
            mBinding.llNext.isVisible = true
        }
    }

    fun setPreviewText(isEdit:String) {
        mBinding.preview.text = isEdit
    }

    fun updateEnable(isEnable:Boolean) {
        mBinding.apply {
            preview.isEnabled = isEnable
            next.isEnabled = isEnable
        }
    }

    interface OnBottomClickListener {
        fun onPreview();
        fun onNext();
        fun onBack();
    }
}